<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Mr_komp_pembayaran extends CI_Controller {

	function __construct() {
        parent::__construct();
        $this->isLogin();
		$this->num_post=10;	
		$this->load->model("master/master_komponen"); 		
	}

	function isLogin(){
		$login=$this->session->userdata('isLogin');
		if(! isset($login)||$login != true){
			$this->session->set_flashdata('error_login', 'Untuk Mengakses Admin Anda Harus Login!');
			redirect('login');	
		}
	}
	
	function popup_komponen(){
		//print_r($_POST);
		$jenis=$_POST['jenis'];//$this->input->post('jenis');
		$data['hasil']=$this->master_komponen->popup($jenis);
		//print_r($data['hasil']);
		$this->load->view('master/mr_komp_pembayaran/popup_pembayaran',$data);
		
	}
	
	function index($offset = 0){
		
		$data['main_view']='master/mr_komp_pembayaran/read';
		$data['aksi_cari']='admin_client/cari_client';
		$uri_segment = 3;
		$num_post=$this->num_post;
		if($offset != 0){
			$offset = $this->uri->segment($uri_segment);
		}else{
			$offset=$offset;
		}
		
		$data['hasil']=$this->master_komponen->read($num_post, $offset);
		$data['offset']=$offset;
		$num_rows = $this->master_komponen->count_all_num_rows();
			
		if($num_rows>0){
			// Membuat pagination
			$config['base_url'] = base_url().'mr_komp_pembayaran/index';
			$config['cur_tag_open'] = '<li class=active><a href="#">';
			$config['cur_tag_close'] = '<span class="sr-only">(current)</span></a></li>';
			$config['num_tag_open'] = '<li>';
			$config['num_tag_close'] = '</li>';
			
			$config['prev_link'] = '<<';
			$config['prev_tag_open'] = '<li>';
			$config['prev_tag_close'] = '</li>';
			
			$config['last_link'] = '>';
			$config['last_tag_open'] = '<li>';
			$config['last_tag_close'] = '</li>';
			
			$config['first_link'] = '<';
			$config['first_tag_open'] = '<li>';
			$config['first_tag_close'] = '</li>';
			
			$config['next_link'] = '>>';
			$config['next_tag_open'] = '<li>';
			$config['next_tag_close'] = '</li>';
			
			$config['total_rows'] = $num_rows;
			$config['per_page'] = $num_post;
			$config['uri_segment'] = $uri_segment;
			$this->pagination->initialize($config);
			$data['pagination'] = $this->pagination->create_links();
		}
		
		$this->load->view('index',$data);
	}
	
	function add()
	{
		$data['main_view']='master/mr_komp_pembayaran/add';
		$this->load->view('index',$data);
	}
	
	function add_exe()
	{
		
		$nama_komp=$this->input->post('nama_komp');
		$jenis_komp=$this->input->post('jenis_komp');
		
		$insert=$this->master_komponen->insert($nama_komp,$jenis_komp);		
		redirect ('mr_komp_pembayaran');
	}	
	
	function edit()
	{
		$id = $this->security->xss_clean($this->uri->segment(3));	
		$data['hasil']=$this->master_komponen->edit($id);		
		$data['main_view']='master/mr_komp_pembayaran/edit';
		$this->load->view('index',$data);
	}
	
	function update()
	{
		$nama_komp=$this->input->post('nama_komp');
		$jenis_komp=$this->input->post('jenis_komp');
		$id=$this->input->post('id');
		$update=$this->master_komponen->update($id,$nama_komp,$jenis_komp);
		redirect('mr_komp_pembayaran');
	}	
	
	function delete()
	{
		$id = $this->security->xss_clean($this->uri->segment(3));
		$this->master_komponen->delete($id);
		redirect('mr_komp_pembayaran');
	}
	
}